import axios from 'axios'
import { jsonp } from '@/assets/js/jsonp'
import { options } from '@/api/config'
// 请求获取热门搜索词
export const getHotSearchInfo = () => {
  return axios.get('http://www.imooc.com/api/search/hot', { timeout: 3000 })
    .then(res => {
      if (res) {
        return res.data.hotKeyWord.def
      }
      throw new Error('未能获取数据')
    })
    .catch(err => {
      if (err) {
        console.log(err)
      }
    })
}
// 请求获取搜索结果
export const getResultInfo = (Searchtext) => {
  const url = 'https://suggest.taobao.com/sug'
  const params = {
    q: Searchtext,
    code: 'utf-8',
    area: 'c2c',
    nick: '',
    sid: null
  }
  return jsonp(url, options, params)
    .then(res => {
      if (res) {
        return res.result
      }
      throw new Error('未能获取数据')
    }).catch(err => {
      if (err) {
        console.log(err)
      }
    })
}
